package com.zhangjie.cmn.controller;


import java.util.Vector;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class TestController {
    public String test(int batch_id) {
        Lock lock = new ReentrantLock();
        Vector<User> vector = new Vector<>();
        User 张杰 = new User(1, 12, "张杰");
        User 张杰2 = new User(2, 12, "张杰吃屎");
        vector.add(张杰);
        try {
            lock.lock();
            //查询数据库
            for (User user : vector) {
                int userBatch_id = user.getBatch_id();
                //判断字段是否存在  是否执行插入
                if (userBatch_id==batch_id){
                    return "batch_id重复了";
                }
            }
            //执行插入
            vector.add(new User(1,batch_id,"成功"));
            return "成功写入";
        } finally {
            lock.unlock();
        }
    }

}
